using System;
using System.Collections;
using System.Collections.Generic;
using Oracle.ManagedDataAccess.Client;
using OracleInternal.Common;
using OracleInternal.Network;
using OracleInternal.ServiceObjects;
using OracleInternal.TTC.Accessors;

namespace OracleInternal.TTC
{
	internal abstract class TTCLob : TTCFunction
	{
		internal const int KPLOB_NONE = 0;

		internal const int KPLOB_GET_LEN = 1;

		internal const int KPLOB_READ = 2;

		internal const int KPLOB_COPY = 4;

		internal const int KPLOB_ERASE = 8;

		internal const int KPLOB_MK_NULL = 16;

		internal const int KPLOB_TRIM = 32;

		internal const int KPLOB_WRITE = 64;

		internal const int KPLOB_APPEND = 128;

		internal const int KPLOB_FILE_OPEN = 256;

		internal const int KPLOB_FILE_CLOSE = 512;

		internal const int KPLOB_FILE_ISOPEN = 1024;

		internal const int KPLOB_FILE_EXISTS = 2048;

		internal const int KPLOB_FILE_CLALL = 4096;

		internal const int KPLOB_LOAD_FROM_FILE = 8192;

		internal const int KPLOB_PAGE_SIZE = 16384;

		internal const int KPLOB_TMP_CREATE = 272;

		internal const int KPLOB_TMP_FREE = 273;

		internal const int KPLOB_TMP_CBK = 17;

		internal const int KPLOB_OPEN = 32768;

		internal const int KPLOB_CLOSE = 65536;

		internal const int KPLOB_ISOPEN = 69632;

		internal const int KPLOB_WRITE_APPEND = 131072;

		internal const int KPLOB_GET_LIMIT = 262144;

		internal const int KPLOB_ARRAY_OPERATION = 524288;

		internal const int KPLOB_GET_OPTIONS = 1048576;

		internal const int KPLOB_SET_OPTIONS = 1048577;

		internal const int KPLOB_GET_SHARED_REG = 1048578;

		internal const int KPLOB_FRAG_INSERT = 2097152;

		internal const int KPLOB_FRAG_DELETE = 2097153;

		internal const int KPLOB_FRAG_MOVE = 2097154;

		internal const int KPLOB_FRAG_REPLACE = 2097155;

		internal const int KPLOB_ARRAY_READ = 524290;

		internal const int KPLOB_ARRAY_TMPFR = 524561;

		internal const int KOLBLLENB = 0;

		internal const int KOLBLVSNB = 2;

		internal const byte QUASI_LOCATOR_VERSION = 4;

		internal const byte KOLBLBLOB = 1;

		internal const byte KOLBLCLOB = 2;

		internal const byte KOLBLNLOB = 4;

		internal const byte KOLBLBFIL = 8;

		internal const byte KOLBLCFIL = 16;

		internal const byte KOLBLNFIL = 32;

		internal const byte KOLBLVBL = 32;

		internal const byte KOLBLABS = 64;

		internal const byte KOLBLPXY = 128;

		internal const byte KOLBLPKEY = 1;

		internal const byte KOLBLIMP = 2;

		internal const byte KOLBLIDX = 4;

		internal const byte KOLBLINI = 8;

		internal const byte KOLBLEMP = 16;

		internal const byte KOLBLVIEW = 32;

		internal const byte KOLBL0FRM = 64;

		internal const byte KOLBL1FRM = 128;

		internal const byte KOLBLRDO = 1;

		internal const byte KOLBLPART = 2;

		internal const byte KOLBLCPD = 4;

		internal const byte KOLBLDIL = 8;

		internal const byte KOLBLBUF = 16;

		internal const byte KOLBLBPS = 32;

		internal const byte KOLBLMOD = 64;

		internal const byte KOLBLVAR = 128;

		internal const byte KOLBLTMP = 1;

		internal const byte KOLBLCACHE = 2;

		internal const byte KOLBLOPEN = 8;

		internal const byte KOLBLRDWR = 16;

		internal const byte KOLBLCLI = 32;

		internal const byte KOLBLVLE = 64;

		internal const byte ALLFLAGS = byte.MaxValue;

		internal const byte KOLBLFLGB = 4;

		internal const byte KOLLIVAR = 6;

		internal const byte KOLLFLG = 4;

		internal const byte KOLL1FLG = 4;

		internal const byte KOLL2FLG = 5;

		internal const byte KOLL3FLG = 6;

		internal const byte KOLL4FLG = 7;

		internal const int KOKL_ORDONLY = 1;

		internal const int KOKL_ORDWR = 2;

		internal const int KOLF_ORDONLY = 11;

		internal const int MODE_READONLY = 0;

		internal const int MODE_READWRITE = 1;

		internal const int DURATION_SESSION = 10;

		internal const int DURATION_CALL = 12;

		internal const int DTYCLOB = 112;

		internal const int DTYBLOB = 113;

		internal const int KOIDSLEN = 8;

		internal const int KOLBLPREL = 2;

		internal const int KOLBLLIDL = 10;

		internal const int KOLBLLIDB = 10;

		internal const int KOLBLTLMXL = 40;

		internal const int MAX_TEMP_LOBS_PER_REQUEST = 25000;

		protected TTCLobData m_lobData;

		protected byte[] m_sourceLobLocator;

		protected byte[] m_destinationLobLocator;

		protected long m_sourceOffset;

		protected long m_destinationOffset;

		protected int m_destinationLength;

		protected short m_characterSet;

		protected long m_lobAmount;

		protected bool m_bLobNull;

		protected long m_lobOperation;

		protected int[] m_lobSCN;

		protected int m_lobSCNLength;

		protected bool m_bSendLobAmount;

		protected byte[] m_outBuffer;

		protected long m_outBufferOffset;

		protected byte[] m_inBuffer;

		protected long m_lobBytesRead;

		protected bool m_bNullO2U;

		protected bool m_variableWidthChar;

		internal TTCLob(MarshallingEngine mEngine)
			: base(mEngine, 96, 0)
		{
			m_lobData = new TTCLobData(mEngine);
		}

		internal static byte[] CreateQuasiLocator(long lobDataLength)
		{
			int num = 40;
			byte[] array = new byte[num];
			array[1] = (byte)(num - 2);
			array[3] = 4;
			byte b = (array[4] = 33);
			array[5] = 8;
			array[9] = 1;
			array[10] = (byte)((lobDataLength >> 56) & 0xFF);
			array[11] = (byte)((lobDataLength >> 48) & 0xFF);
			array[12] = (byte)((lobDataLength >> 40) & 0xFF);
			array[13] = (byte)((lobDataLength >> 32) & 0xFF);
			array[14] = (byte)((lobDataLength >> 24) & 0xFF);
			array[15] = (byte)((lobDataLength >> 16) & 0xFF);
			array[16] = (byte)((lobDataLength >> 8) & 0xFF);
			array[17] = (byte)(lobDataLength & 0xFF);
			return array;
		}

		internal abstract byte[] CreateTemporaryLob(bool bCache, bool bNClob, int duration);

		internal virtual void FreeTemporaryLob(byte[] lobLocator)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.TTCLob, OracleTraceFuncName.FreeTemporaryLob);
			}
			try
			{
				if (!IsQuasiLocator(lobLocator) && IsTemporaryLob(lobLocator))
				{
					Initialize();
					m_lobOperation = 273L;
					m_sourceLobLocator = lobLocator;
					WriteFunctionHeader();
					WriteLobOperation();
					m_marshallingEngine.m_oraBufWriter.FlushData();
					ReceiveResponse();
				}
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268566528, OracleTraceClassName.TTCLob, OracleTraceFuncName.FreeTemporaryLob, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.TTCLob, OracleTraceFuncName.FreeTemporaryLob);
				}
			}
		}

		internal bool OpenLob(byte[] lobLocator, int mode, int lobOperation)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.TTCLob, OracleTraceFuncName.OpenLob);
			}
			bool result = false;
			try
			{
				if (2 == mode && IsReadOnly(lobLocator))
				{
					throw new OracleException(24823, string.Empty, string.Empty, OracleStringResourceManager.GetErrorMesg(24823));
				}
				if (IsQuasiLocator(lobLocator))
				{
					return result;
				}
				if ((lobLocator[7] & 1) == 1 || (lobLocator[4] & 0x40) == 64)
				{
					if ((lobLocator[7] & 8) == 8)
					{
						throw new Exception("TTC Error");
					}
					lobLocator[7] |= 8;
					if (mode == 2)
					{
						lobLocator[7] |= 16;
					}
					result = true;
				}
				else
				{
					Initialize();
					m_sourceLobLocator = lobLocator;
					m_lobOperation = lobOperation;
					m_lobAmount = mode;
					m_bSendLobAmount = true;
					WriteFunctionHeader();
					WriteLobOperation();
					m_marshallingEngine.m_oraBufWriter.FlushData();
					ReceiveResponse();
					if (m_lobAmount != 0L)
					{
						result = true;
					}
				}
				return result;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268566528, OracleTraceClassName.TTCLob, OracleTraceFuncName.OpenLob, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.TTCLob, OracleTraceFuncName.OpenLob);
				}
			}
		}

		internal bool CloseLob(byte[] lobLocator, int lobOperation)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.TTCLob, OracleTraceFuncName.CloseLob);
			}
			bool result = true;
			try
			{
				if (IsQuasiLocator(lobLocator))
				{
					return result;
				}
				if ((lobLocator[7] & 1) == 1 || (lobLocator[4] & 0x40) == 64)
				{
					if ((lobLocator[7] & 8) != 8)
					{
						throw new Exception("TTC Error");
					}
					lobLocator[7] &= 231;
				}
				else
				{
					Initialize();
					m_sourceLobLocator = lobLocator;
					m_lobOperation = lobOperation;
					WriteFunctionHeader();
					WriteLobOperation();
					m_marshallingEngine.m_oraBufWriter.FlushData();
					ReceiveResponse();
				}
				return result;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268566528, OracleTraceClassName.TTCLob, OracleTraceFuncName.CloseLob, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.TTCLob, OracleTraceFuncName.CloseLob);
				}
			}
		}

		internal static bool IsTemporaryLob(byte[] lobLocator)
		{
			if ((lobLocator[7] & 1) == 1 || (lobLocator[4] & 0x40) == 64 || IsValueBasedLocator(lobLocator) || IsQuasiLocator(lobLocator))
			{
				return true;
			}
			return false;
		}

		internal long GetChunkSize(byte[] lobLocator)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.TTCLob, OracleTraceFuncName.GetChunkSize);
			}
			try
			{
				Initialize();
				m_lobOperation = 16384L;
				m_sourceLobLocator = lobLocator;
				WriteFunctionHeader();
				m_bSendLobAmount = true;
				WriteLobOperation();
				m_marshallingEngine.m_oraBufWriter.FlushData();
				ReceiveResponse();
				return m_lobAmount;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268566528, OracleTraceClassName.TTCLob, OracleTraceFuncName.GetChunkSize, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.TTCLob, OracleTraceFuncName.GetChunkSize);
				}
			}
		}

		internal long GetLength(byte[] lobLocator)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.TTCLob, OracleTraceFuncName.GetLength);
			}
			try
			{
				Initialize();
				m_lobOperation = 1L;
				m_sourceLobLocator = lobLocator;
				m_bSendLobAmount = true;
				WriteFunctionHeader();
				WriteLobOperation();
				m_marshallingEngine.m_oraBufWriter.FlushData();
				ReceiveResponse();
				return m_lobAmount;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268566528, OracleTraceClassName.TTCLob, OracleTraceFuncName.GetLength, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.TTCLob, OracleTraceFuncName.GetLength);
				}
			}
		}

		internal long Trim(byte[] lobLocator, long newLength)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.TTCLob, OracleTraceFuncName.Trim);
			}
			try
			{
				if (IsReadOnly(lobLocator))
				{
					throw new OracleException(24823, string.Empty, string.Empty, OracleStringResourceManager.GetErrorMesg(24823));
				}
				if (IsQuasiOrTempVBL(lobLocator))
				{
					throw new OracleException(24822, string.Empty, string.Empty, OracleStringResourceManager.GetErrorMesg(24822));
				}
				Initialize();
				m_lobOperation = 32L;
				m_sourceLobLocator = lobLocator;
				m_lobAmount = newLength;
				m_bSendLobAmount = true;
				WriteFunctionHeader();
				WriteLobOperation();
				m_marshallingEngine.m_oraBufWriter.FlushData();
				ReceiveResponse();
				return m_lobAmount;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268566528, OracleTraceClassName.TTCLob, OracleTraceFuncName.Trim, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.TTCLob, OracleTraceFuncName.Trim);
				}
			}
		}

		internal static void FreeTempLobsPiggyBack(MarshallingEngine marshallingEngine, ArrayList lobLocators)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.TTCLob, OracleTraceFuncName.FreeTempLobsPiggyBack);
			}
			int count = lobLocators.Count;
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			int num4 = 524561;
			try
			{
				do
				{
					num3 = 0;
					for (int i = num; i < count; i++)
					{
						num3 += ((byte[])lobLocators[i]).Length;
						num2++;
						if (num2 >= 25000)
						{
							break;
						}
					}
					marshallingEngine.MarshalUB1(17);
					marshallingEngine.MarshalUB1(96);
					marshallingEngine.MarshalUB1(0);
					marshallingEngine.MarshalPointer();
					marshallingEngine.MarshalSB4(num3);
					marshallingEngine.MarshalNullPointer();
					marshallingEngine.MarshalSB4(0);
					marshallingEngine.MarshalUB4(0L);
					marshallingEngine.MarshalUB4(0L);
					marshallingEngine.MarshalNullPointer();
					marshallingEngine.MarshalNullPointer();
					marshallingEngine.MarshalNullPointer();
					marshallingEngine.MarshalUB4(num4);
					marshallingEngine.MarshalNullPointer();
					marshallingEngine.MarshalSB4(0);
					marshallingEngine.MarshalSB8(0L);
					marshallingEngine.MarshalSB8(0L);
					marshallingEngine.MarshalNullPointer();
					marshallingEngine.MarshalNullPointer();
					marshallingEngine.MarshalSWORD(0);
					marshallingEngine.MarshalNullPointer();
					marshallingEngine.MarshalSWORD(0);
					marshallingEngine.MarshalNullPointer();
					marshallingEngine.MarshalSWORD(0);
					for (int j = num; j < num + num2; j++)
					{
						marshallingEngine.MarshalB1Array((byte[])lobLocators[j]);
					}
					num += num2;
					num2 = 0;
				}
				while (num < count);
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268566528, OracleTraceClassName.TTCLob, OracleTraceFuncName.FreeTempLobsPiggyBack, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.TTCLob, OracleTraceFuncName.FreeTempLobsPiggyBack);
				}
			}
		}

		internal void LobArrayRead(TTCLobAccessor[] accessorForLOBCols, byte[][] lobLocators, long[] lobAmounts, long[] lobOffsets, int numLobsToSend, int numOfLobColumns)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.TTCLob, OracleTraceFuncName.LobArrayRead);
			}
			try
			{
				Initialize();
				m_lobOperation = 524290L;
				WriteFunctionHeader();
				WriteLobArrayOperation(lobLocators, lobAmounts, lobOffsets, numLobsToSend);
				m_marshallingEngine.m_oraBufWriter.FlushData();
				m_marshallingEngine.m_oraBufRdr.m_bHoldOBTemporarily = true;
				LobArrayReceiveResponse(accessorForLOBCols, lobLocators, numOfLobColumns);
				if (m_marshallingEngine.m_oraBufRdr.m_currentOB != null)
				{
					m_marshallingEngine.m_oraBufRdr.m_tempOBList.Add(m_marshallingEngine.m_oraBufRdr.m_currentOB);
					m_marshallingEngine.m_oraBufRdr.m_currentOB = null;
				}
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268566528, OracleTraceClassName.TTCLob, OracleTraceFuncName.LobArrayRead, ex);
				throw;
			}
			finally
			{
				m_marshallingEngine.m_oraBufRdr.m_bHoldOBTemporarily = false;
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.TTCLob, OracleTraceFuncName.LobArrayRead);
				}
			}
		}

		internal long Read(byte[] lobLocator, long locatorOffset, long numBytesToRead, long outBufferOffset, ref byte[] outBuffer)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.TTCLob, OracleTraceFuncName.Read);
			}
			try
			{
				Initialize();
				m_lobOperation = 2L;
				m_sourceLobLocator = lobLocator;
				m_sourceOffset = locatorOffset;
				m_lobAmount = numBytesToRead;
				m_bSendLobAmount = true;
				m_outBuffer = outBuffer;
				m_outBufferOffset = outBufferOffset;
				WriteFunctionHeader();
				WriteLobOperation();
				m_marshallingEngine.m_oraBufWriter.FlushData();
				ReceiveResponse();
				return m_lobBytesRead;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268566528, OracleTraceClassName.TTCLob, OracleTraceFuncName.Read, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.TTCLob, OracleTraceFuncName.Read);
				}
			}
		}

		internal long Write(byte[] lobLocator, long locatorOffset, byte[] inBuffer, long inBufferOffset, long numBytesToWrite)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.TTCLob, OracleTraceFuncName.Write);
			}
			try
			{
				if (IsReadOnly(lobLocator))
				{
					throw new OracleException(24823, string.Empty, string.Empty, OracleStringResourceManager.GetErrorMesg(24823));
				}
				if (IsQuasiOrTempVBL(lobLocator))
				{
					throw new OracleException(24822, string.Empty, string.Empty, OracleStringResourceManager.GetErrorMesg(24822));
				}
				Initialize();
				m_lobOperation = 64L;
				m_sourceLobLocator = lobLocator;
				m_sourceOffset = locatorOffset;
				m_lobAmount = numBytesToWrite;
				m_bSendLobAmount = true;
				m_inBuffer = inBuffer;
				WriteFunctionHeader();
				WriteLobOperation();
				m_lobData.WriteLobData(inBuffer, inBufferOffset, numBytesToWrite);
				m_marshallingEngine.m_oraBufWriter.FlushData();
				ReceiveResponse();
				return m_lobAmount;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268566528, OracleTraceClassName.TTCLob, OracleTraceFuncName.Write, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.TTCLob, OracleTraceFuncName.Write);
				}
			}
		}

		internal void Append(byte[] srcLobLocator, byte[] destLobLocator)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.TTCLob, OracleTraceFuncName.Append);
			}
			try
			{
				if (IsReadOnly(srcLobLocator))
				{
					throw new OracleException(24823, string.Empty, string.Empty, OracleStringResourceManager.GetErrorMesg(24823));
				}
				if (IsQuasiOrTempVBL(srcLobLocator))
				{
					throw new OracleException(24822, string.Empty, string.Empty, OracleStringResourceManager.GetErrorMesg(24822));
				}
				Initialize();
				m_lobOperation = 128L;
				m_sourceLobLocator = srcLobLocator;
				m_destinationLobLocator = destLobLocator;
				WriteFunctionHeader();
				WriteLobOperation();
				m_marshallingEngine.m_oraBufWriter.FlushData();
				ReceiveResponse();
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268566528, OracleTraceClassName.TTCLob, OracleTraceFuncName.Append, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.TTCLob, OracleTraceFuncName.Append);
				}
			}
		}

		internal long Copy(byte[] srcLobLocator, byte[] destLobLocator, long srcOffset, long destOffset, long srcLength)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.TTCLob, OracleTraceFuncName.Copy);
			}
			try
			{
				if (IsReadOnly(destLobLocator))
				{
					throw new OracleException(24823, string.Empty, string.Empty, OracleStringResourceManager.GetErrorMesg(24823));
				}
				if (IsQuasiOrTempVBL(destLobLocator))
				{
					throw new OracleException(24822, string.Empty, string.Empty, OracleStringResourceManager.GetErrorMesg(24822));
				}
				Initialize();
				m_lobOperation = 4L;
				m_sourceLobLocator = srcLobLocator;
				m_destinationLobLocator = destLobLocator;
				m_sourceOffset = srcOffset;
				m_destinationOffset = destOffset;
				m_lobAmount = srcLength;
				m_bSendLobAmount = true;
				WriteFunctionHeader();
				WriteLobOperation();
				m_marshallingEngine.m_oraBufWriter.FlushData();
				ReceiveResponse();
				return m_lobAmount;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268566528, OracleTraceClassName.TTCLob, OracleTraceFuncName.Copy, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.TTCLob, OracleTraceFuncName.Copy);
				}
			}
		}

		internal long Erase(byte[] lobLocator, long locatorOffset, long numBytesToErase)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.TTCLob, OracleTraceFuncName.Erase);
			}
			try
			{
				if (IsReadOnly(lobLocator))
				{
					throw new OracleException(24823, string.Empty, string.Empty, OracleStringResourceManager.GetErrorMesg(24823));
				}
				if (IsQuasiOrTempVBL(lobLocator))
				{
					throw new OracleException(24822, string.Empty, string.Empty, OracleStringResourceManager.GetErrorMesg(24822));
				}
				Initialize();
				m_lobOperation = 8L;
				m_sourceLobLocator = lobLocator;
				m_sourceOffset = locatorOffset;
				m_lobAmount = numBytesToErase;
				m_bSendLobAmount = true;
				WriteFunctionHeader();
				WriteLobOperation();
				m_marshallingEngine.m_oraBufWriter.FlushData();
				ReceiveResponse();
				return m_lobAmount;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268566528, OracleTraceClassName.TTCLob, OracleTraceFuncName.Erase, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.TTCLob, OracleTraceFuncName.Erase);
				}
			}
		}

		internal void WriteLobArrayOperation(byte[][] lobLocators, long[] lobAmounts, long[] lobOffsets, int numLobsToSend)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.TTCLob, OracleTraceFuncName.WriteLobArrayOperation);
			}
			try
			{
				m_sourceLobLocator = new byte[1];
				m_marshallingEngine.MarshalPointer();
				m_marshallingEngine.MarshalSB4(1);
				m_marshallingEngine.MarshalNullPointer();
				m_marshallingEngine.MarshalSB4(0);
				m_marshallingEngine.MarshalUB4(0L);
				m_marshallingEngine.MarshalUB4(0L);
				if (m_characterSet != 0)
				{
					m_marshallingEngine.MarshalPointer();
				}
				else
				{
					m_marshallingEngine.MarshalNullPointer();
				}
				m_marshallingEngine.MarshalNullPointer();
				m_marshallingEngine.MarshalNullPointer();
				m_marshallingEngine.MarshalUB4(m_lobOperation);
				m_marshallingEngine.MarshalNullPointer();
				m_marshallingEngine.MarshalSB4(0);
				m_marshallingEngine.MarshalSB8(0L);
				m_marshallingEngine.MarshalSB8(0L);
				m_marshallingEngine.MarshalNullPointer();
				m_marshallingEngine.MarshalPointer();
				int num = 0;
				for (int i = 0; i < lobLocators.Length; i++)
				{
					if (lobLocators[i] != null)
					{
						num += lobLocators[i].Length;
					}
				}
				m_marshallingEngine.MarshalSWORD(num);
				m_marshallingEngine.MarshalPointer();
				m_marshallingEngine.MarshalSWORD(numLobsToSend);
				m_marshallingEngine.MarshalPointer();
				m_marshallingEngine.MarshalSWORD(numLobsToSend);
				m_marshallingEngine.MarshalB1Array(m_sourceLobLocator);
				for (int j = 0; j < lobLocators.Length; j++)
				{
					if (lobLocators[j] != null)
					{
						m_marshallingEngine.MarshalB1Array(lobLocators[j]);
					}
				}
				for (int k = 0; k < lobAmounts.Length; k++)
				{
					if (-1 != lobAmounts[k])
					{
						m_marshallingEngine.MarshalSB8(lobAmounts[k]);
					}
				}
				for (int l = 0; l < lobOffsets.Length; l++)
				{
					if (-1 != lobOffsets[l])
					{
						m_marshallingEngine.MarshalSB8(lobOffsets[l]);
					}
				}
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268566528, OracleTraceClassName.TTCLob, OracleTraceFuncName.WriteLobArrayOperation, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.TTCLob, OracleTraceFuncName.WriteLobArrayOperation);
				}
			}
		}

		internal void LobArrayReceiveResponse(TTCLobAccessor[] accessorForLOBCols, byte[][] lobLocators, int numOfLobColumns)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.TTCLob, OracleTraceFuncName.LobArrayReceiveResponse);
			}
			bool flag = false;
			byte b = 0;
			int num = 0;
			int num2 = -1;
			try
			{
				m_marshallingEngine.TTCErrorObject.Initialize();
				while (!flag)
				{
					try
					{
						switch (m_marshallingEngine.UnmarshalSB1())
						{
						case 23:
							ProcessServerSidePiggybackFunction(0);
							break;
						case 14:
						{
							m_marshallingEngine.m_oraBufRdr.StartAccumulatingColumnData(null, 0);
							m_lobBytesRead = m_lobData.ReadLobDataForArray();
							int num3 = num % numOfLobColumns;
							if (num3 == 0)
							{
								num2++;
							}
							while (lobLocators[num] == null)
							{
								accessorForLOBCols[num3].m_dataThroughLobArrayRead[num2] = null;
								num++;
								num3 = num % numOfLobColumns;
								if (num3 == 0)
								{
									num2++;
								}
							}
							accessorForLOBCols[num3].m_dataThroughLobArrayRead[num2] = m_marshallingEngine.m_oraBufRdr.m_dataSegments;
							num++;
							m_marshallingEngine.m_oraBufRdr.StopAccumulatingColumnData();
							break;
						}
						case 8:
							Process_RPA_Message(lobLocators);
							break;
						case 15:
							m_marshallingEngine.TTCErrorObject.ReadWarning();
							break;
						case 4:
							flag = true;
							m_marshallingEngine.TTCErrorObject.ReadErrorMessage();
							if (m_marshallingEngine.TTCErrorObject.ErrorCode == 1403)
							{
								m_marshallingEngine.TTCErrorObject.Initialize();
							}
							else
							{
								OracleConnectionImpl.CheckForAnyErrorFromDB(m_marshallingEngine.TTCErrorObject);
							}
							break;
						case 9:
							if (m_marshallingEngine.HasEOCSCapability)
							{
								m_marshallingEngine.m_endOfCallStatus = m_marshallingEngine.UnmarshalUB4();
							}
							flag = true;
							break;
						default:
							throw new Exception("TTC error");
						}
					}
					catch (NetworkException ex)
					{
						if (ex.ErrorCode != 3111)
						{
							throw;
						}
						m_marshallingEngine.m_oracleCommunication.Reset();
					}
					catch (Exception)
					{
						if (m_marshallingEngine.m_oraBufRdr != null)
						{
							m_marshallingEngine.m_oraBufRdr.ClearState();
						}
						if (!flag)
						{
							m_marshallingEngine.m_oracleCommunication.Break();
							m_marshallingEngine.m_oracleCommunication.Reset();
							continue;
						}
						throw;
					}
				}
			}
			catch (Exception ex3)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268566528, OracleTraceClassName.TTCLob, OracleTraceFuncName.LobArrayReceiveResponse, ex3);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.TTCLob, OracleTraceFuncName.LobArrayReceiveResponse);
				}
			}
		}

		internal void WriteLobOperation()
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.TTCLob, OracleTraceFuncName.WriteLobOperation);
			}
			int val = 0;
			try
			{
				if (m_sourceLobLocator != null)
				{
					val = m_sourceLobLocator.Length;
					m_marshallingEngine.MarshalPointer();
				}
				else
				{
					m_marshallingEngine.MarshalNullPointer();
				}
				m_marshallingEngine.MarshalSB4(val);
				if (m_destinationLobLocator != null)
				{
					m_destinationLength = m_destinationLobLocator.Length;
					m_marshallingEngine.MarshalPointer();
				}
				else
				{
					m_marshallingEngine.MarshalNullPointer();
				}
				m_marshallingEngine.MarshalSB4(m_destinationLength);
				if (m_marshallingEngine.NegotiatedTTCVersion >= 3)
				{
					m_marshallingEngine.MarshalUB4(0L);
				}
				else
				{
					m_marshallingEngine.MarshalUB4(m_sourceOffset);
				}
				if (m_marshallingEngine.NegotiatedTTCVersion >= 3)
				{
					m_marshallingEngine.MarshalUB4(0L);
				}
				else
				{
					m_marshallingEngine.MarshalUB4(m_destinationOffset);
				}
				if (m_characterSet != 0)
				{
					m_marshallingEngine.MarshalPointer();
				}
				else
				{
					m_marshallingEngine.MarshalNullPointer();
				}
				if (m_bSendLobAmount && m_marshallingEngine.NegotiatedTTCVersion < 3)
				{
					m_marshallingEngine.MarshalPointer();
				}
				else
				{
					m_marshallingEngine.MarshalNullPointer();
				}
				if (m_bNullO2U)
				{
					m_marshallingEngine.MarshalPointer();
				}
				else
				{
					m_marshallingEngine.MarshalNullPointer();
				}
				m_marshallingEngine.MarshalUB4(m_lobOperation);
				if (m_lobSCNLength != 0)
				{
					m_marshallingEngine.MarshalPointer();
				}
				else
				{
					m_marshallingEngine.MarshalNullPointer();
				}
				m_marshallingEngine.MarshalSB4(m_lobSCNLength);
				if (m_marshallingEngine.NegotiatedTTCVersion >= 3)
				{
					m_marshallingEngine.MarshalSB8(m_sourceOffset);
					m_marshallingEngine.MarshalSB8(m_destinationOffset);
					if (m_bSendLobAmount)
					{
						m_marshallingEngine.MarshalPointer();
					}
					else
					{
						m_marshallingEngine.MarshalNullPointer();
					}
					if (m_marshallingEngine.NegotiatedTTCVersion >= 4)
					{
						m_marshallingEngine.MarshalNullPointer();
						m_marshallingEngine.MarshalSWORD(0);
						m_marshallingEngine.MarshalNullPointer();
						m_marshallingEngine.MarshalSWORD(0);
						m_marshallingEngine.MarshalNullPointer();
						m_marshallingEngine.MarshalSWORD(0);
					}
				}
				if (m_sourceLobLocator != null)
				{
					m_marshallingEngine.MarshalB1Array(m_sourceLobLocator);
				}
				if (m_destinationLobLocator != null)
				{
					m_marshallingEngine.MarshalB1Array(m_destinationLobLocator);
				}
				if (m_characterSet != 0)
				{
					m_marshallingEngine.MarshalUB2(m_characterSet);
				}
				if (m_bSendLobAmount && m_marshallingEngine.NegotiatedTTCVersion < 3)
				{
					m_marshallingEngine.MarshalUB4(m_lobAmount);
				}
				if (m_lobSCNLength != 0)
				{
					for (int i = 0; i < m_lobSCNLength; i++)
					{
						m_marshallingEngine.MarshalUB4(m_lobSCN[i]);
					}
				}
				if (m_bSendLobAmount && m_marshallingEngine.NegotiatedTTCVersion >= 3)
				{
					m_marshallingEngine.MarshalSB8(m_lobAmount);
				}
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268566528, OracleTraceClassName.TTCLob, OracleTraceFuncName.WriteLobOperation, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.TTCLob, OracleTraceFuncName.WriteLobOperation);
				}
			}
		}

		internal void ReceiveResponse(List<ArraySegment<byte>> dataSegments = null)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.TTCLob, OracleTraceFuncName.ReceiveResponse);
			}
			bool flag = false;
			byte b = 0;
			try
			{
				m_marshallingEngine.TTCErrorObject.Initialize();
				while (!flag)
				{
					try
					{
						switch (m_marshallingEngine.UnmarshalSB1())
						{
						case 23:
							ProcessServerSidePiggybackFunction(0);
							break;
						case 8:
							Process_RPA_Message(null);
							break;
						case 14:
							if (dataSegments != null)
							{
								m_marshallingEngine.m_oraBufRdr.StartAccumulatingColumnData(dataSegments);
								m_lobData.ReadLobDataForArray();
								m_marshallingEngine.m_oraBufRdr.StopAccumulatingColumnData();
							}
							else
							{
								m_lobBytesRead = m_lobData.ReadLobData(m_outBuffer, m_outBufferOffset);
							}
							break;
						case 15:
							m_marshallingEngine.TTCErrorObject.ReadWarning();
							break;
						case 4:
							flag = true;
							m_marshallingEngine.TTCErrorObject.ReadErrorMessage();
							if (m_marshallingEngine.TTCErrorObject.ErrorCode == 1403)
							{
								m_marshallingEngine.TTCErrorObject.Initialize();
							}
							else
							{
								OracleConnectionImpl.CheckForAnyErrorFromDB(m_marshallingEngine.TTCErrorObject);
							}
							break;
						case 9:
							if (m_marshallingEngine.HasEOCSCapability)
							{
								m_marshallingEngine.m_endOfCallStatus = m_marshallingEngine.UnmarshalUB4();
							}
							flag = true;
							break;
						default:
							throw new Exception("TTC error");
						}
					}
					catch (NetworkException ex)
					{
						if (ex.ErrorCode != 3111)
						{
							throw;
						}
						m_marshallingEngine.m_oracleCommunication.Reset();
					}
					catch (Exception)
					{
						if (m_marshallingEngine.m_oraBufRdr != null)
						{
							m_marshallingEngine.m_oraBufRdr.ClearState();
						}
						if (!flag)
						{
							m_marshallingEngine.m_oracleCommunication.Break();
							m_marshallingEngine.m_oracleCommunication.Reset();
							continue;
						}
						throw;
					}
				}
			}
			catch (Exception ex3)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268566528, OracleTraceClassName.TTCLob, OracleTraceFuncName.ReceiveResponse, ex3);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.TTCLob, OracleTraceFuncName.ReceiveResponse);
				}
			}
		}

		private void Process_RPA_Message(byte[][] lobLocators)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.TTCLob, OracleTraceFuncName.Process_RPA_Message);
			}
			try
			{
				if (m_sourceLobLocator != null)
				{
					m_marshallingEngine.GetNBytes(m_sourceLobLocator, 0, m_sourceLobLocator.Length);
				}
				if (m_destinationLobLocator != null)
				{
					m_marshallingEngine.GetNBytes(m_destinationLobLocator, 0, m_destinationLobLocator.Length);
				}
				if (m_characterSet != 0)
				{
					m_characterSet = m_marshallingEngine.UnmarshalSB2();
				}
				if (m_bSendLobAmount)
				{
					if (m_marshallingEngine.NegotiatedTTCVersion >= 3)
					{
						m_lobAmount = m_marshallingEngine.UnmarshalSB8();
					}
					else
					{
						m_lobAmount = m_marshallingEngine.UnmarshalUB4();
					}
				}
				if (m_bNullO2U && m_marshallingEngine.UnmarshalSB2() != 0)
				{
					m_bLobNull = true;
				}
				if (lobLocators == null)
				{
					return;
				}
				byte[] array = null;
				for (int i = 0; i < lobLocators.Length; i++)
				{
					for (array = lobLocators[i]; array == null; array = lobLocators[i])
					{
						i++;
						if (i >= lobLocators.Length)
						{
							break;
						}
					}
					if (array != null)
					{
						m_marshallingEngine.GetNBytes(array, 0, array.Length);
					}
				}
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268566528, OracleTraceClassName.TTCLob, OracleTraceFuncName.Process_RPA_Message, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.TTCLob, OracleTraceFuncName.Process_RPA_Message);
				}
			}
		}

		internal void Initialize()
		{
			m_sourceLobLocator = null;
			m_destinationLobLocator = null;
			m_sourceOffset = 0L;
			m_destinationOffset = 0L;
			m_destinationLength = 0;
			m_characterSet = 0;
			m_lobAmount = 0L;
			m_bLobNull = false;
			m_lobOperation = 0L;
			m_lobSCN = null;
			m_lobSCNLength = 0;
			m_bSendLobAmount = false;
			m_bNullO2U = false;
			m_lobBytesRead = 0L;
			m_variableWidthChar = false;
			m_outBuffer = null;
			m_outBufferOffset = 0L;
			m_inBuffer = null;
		}

		internal static byte[] GetLobId(byte[] lobLocator)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.TTCLob, OracleTraceFuncName.GetLobId);
			}
			byte[] array = new byte[10];
			try
			{
				Array.Copy(lobLocator, 10, array, 0, 10);
				return array;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.TTCLob, OracleTraceFuncName.GetLobId);
				}
			}
		}

		internal static string GetLobIdString(byte[] lobLocator)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131328, OracleTraceClassName.TTCLob, OracleTraceFuncName.GetLobIdString);
			}
			try
			{
				return BitConverter.ToString(lobLocator, 10, 10);
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)131584, OracleTraceClassName.TTCLob, OracleTraceFuncName.GetLobIdString);
				}
			}
		}

		internal static bool IsValueBasedLocator(byte[] lobLocator)
		{
			return (lobLocator[4] & 0x20) == 32;
		}

		internal static bool IsQuasiLocator(byte[] lobLocator)
		{
			return lobLocator[3] == 4;
		}

		internal static bool IsReadOnly(byte[] lobLocator)
		{
			return (lobLocator[6] & 1) == 1;
		}

		internal static bool IsQuasiOrTempVBL(byte[] lobLocator)
		{
			if (IsValueBasedLocator(lobLocator))
			{
				if (!IsTemporaryLob(lobLocator))
				{
					return IsQuasiLocator(lobLocator);
				}
				return true;
			}
			return false;
		}
	}
}
